﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Entities;
using Utility;
using BUS;

public partial class Administrator_dathang : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            load_data();
        }
    }
    private void load_data()
    {
        pager.PageSize = 15;
        Criteria c = new Criteria();
        int total = 0;
        try
        {
            int id = int.Parse(Request.QueryString["iddh"].ToString());
                c.add(Condition.AND, Tbl_DatHang_Columns.MaDatHang, Condition.EQUAL,id);
        }
        catch { }
        Tbl_DatHang_Collection dhCollection =
               Tbl_DatHang_BUS.Get(c.Criter, pager.CurrentIndex, pager.PageSize,
               Tbl_DatHang_Columns.STT.ToString(), OrderDirection.ASC.ToString(), out total);
        Repeater1.DataSource = dhCollection;
        Repeater1.DataBind();

        pager.ItemCount = total;
    }

    protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.AlternatingItem ||
                  e.Item.ItemType == ListItemType.Item)
        {
            Tbl_DatHang_Entities dh = (Tbl_DatHang_Entities)e.Item.DataItem;
            HyperLink hyp_nguoimua = (HyperLink)e.Item.FindControl("hyp_nguoimua");
            HyperLink hyp_tensanpham = (HyperLink)e.Item.FindControl("hyp_tensanpham");
            Literal lit_stt = (Literal)e.Item.FindControl("lit_stt");
            CheckBox chkb_dagiao = (CheckBox)e.Item.FindControl("chkb_dagiao");

            lit_stt.Text = dh.STT.ToString();

            if (dh.DaGiao == true)
            {
                chkb_dagiao.Checked = true;
            }
            else
            {
                chkb_dagiao.Checked = false;
            }
           
            Tbl_sanpham_Entities sp = Tbl_sanpham_BUS.GetByID(dh.STT_sanpham);
            hyp_tensanpham.NavigateUrl = "~/Administrator/sanpham_chitiet.aspx?id=" + dh.STT_sanpham;
            hyp_tensanpham.Text = sp.TenSP;

            Tbl_khachhang_Entities kh = Tbl_khachhang_BUS.GetByID(dh.NguoiMua);
            hyp_nguoimua.NavigateUrl = "~/Administrator/khachhang.aspx?id=" + dh.NguoiMua;
            hyp_nguoimua.Text = kh.TenDangNhap;
        }
    }
}
